//
//  HLGiftCollectionCell.m
//  YueYue
//
//  Created by hulu001 on 2023/6/2.
//

#import "HLGiftCollectionCell.h"

@interface HLGiftCollectionCell ()

@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIImageView *giftImageView;
@property (nonatomic, strong) UILabel *giftNameLabel;
@property (nonatomic, strong) UILabel *giftPriceLabel;

@end

@implementation HLGiftCollectionCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        self.backgroundColor= UIColor.whiteColor;
        [self setupView];
    }
    return self;
    
}

- (void)setupView
{
    self.backView = [[UIView alloc] init];
    _backView.layer.masksToBounds = YES;
    _backView.layer.cornerRadius = 4;
    _backView.layer.borderColor = UIColor.whiteColor.CGColor;
    _backView.layer.borderWidth = 2;
    [self.contentView addSubview:_backView];
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    self.giftImageView = [UIImageView.alloc init];
    _giftImageView.image = UIImageMake(@"mine_chong");
    _giftImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_giftImageView];
    [_giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(6);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(48);
    }];
    
    self.giftNameLabel = [[UILabel alloc] init];
    _giftNameLabel.textColor = [UIColor qmui_colorWithHexString:@"#191919"];
    _giftNameLabel.font = UIFontMake(14);
    _giftNameLabel.text = @"加载中";
    _giftNameLabel.textAlignment = NSTextAlignmentCenter;
    _giftNameLabel.numberOfLines = 0;
    [self.contentView addSubview:_giftNameLabel];
    [_giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(_giftImageView.mas_bottom).offset(6);
    }];
    
    self.giftPriceLabel = [[UILabel alloc] init];
    _giftPriceLabel.textColor = [UIColor qmui_colorWithHexString:@"#A2A6B0"];
    _giftPriceLabel.font = UIFontMake(11);
    _giftPriceLabel.text = @"20金币";
    _giftPriceLabel.textAlignment = NSTextAlignmentCenter;
    _giftPriceLabel.numberOfLines = 0;
    [self.contentView addSubview:_giftPriceLabel];
    [_giftPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(_giftNameLabel.mas_bottom).offset(6);
    }];
    
}


-(void)setModel:(HLGiftModel *)model
{
    
    
    if(model.giftListType == HLGiftListTypeBag){
        [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.activeGiftUrl]];
        self.giftNameLabel.text = model.activeGiftName;
        self.giftPriceLabel.text = [NSString stringWithFormat:@"%@%@",model.activeGiftQuantity, @"个"];
    } else {
        [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.giftImgLink]];
        self.giftNameLabel.text = model.giftName;
        self.giftPriceLabel.text = [NSString stringWithFormat:@"%@%@",model.giftAmount, @"金币"];
    }
    
    if (model.isChange) {
        self.backView.backgroundColor = [UIColor qmui_colorWithHexString:@"#FFF2FB"];
        self.backView.layer.borderColor = HLMainColor.CGColor;
        self.backView.layer.borderWidth = 2;
        self.giftNameLabel.textColor = HLMainColor;
        self.giftNameLabel.font = UIFontMediumMake(14);
        self.giftPriceLabel.textColor = [UIColor qmui_colorWithHexString:@"#1A1A1A"];
    }else{
        self.backView.backgroundColor = UIColor.whiteColor;
        self.backView.layer.borderColor = UIColorBlack.CGColor;
        self.backView.layer.borderWidth = 0;
        self.giftNameLabel.textColor = [UIColor qmui_colorWithHexString:@"#191919"];
        self.giftNameLabel.font = UIFontMake(14);
        self.giftPriceLabel.textColor = [UIColor qmui_colorWithHexString:@"#A2A6B0"];
    }
  
    
}

- (void)setCellHidden:(BOOL)isHidden
{
    self.giftImageView.hidden = isHidden;
    self.giftNameLabel.hidden = isHidden;
    self.giftPriceLabel.hidden = isHidden;
    self.backView.hidden = isHidden;
}

@end
